<?php
  require_once "function.php";
  $targetdate=getdate(time()-180*24*3600);
  $currentdate=getdate();

  $url1="http://ihisaw.ntuh.gov.tw/WebApplication/OtherIndependentProj/PatientBasicInfoEdit/PatientMedicalRecordListQuery.aspx?SESSION=".$sessionid;

  $hidden=viewstate($url1);
  $r=new HttpRequest($url1);
  $r->setMethod(HTTP_METH_POST);
  $data=array('scrollLeft'=>'','scrollTop'=>'','__LASTFOCUS'=>'','NTUHWeb1$ChartInputTextBox'=>$_GET['id'],'__EVENTTARGET'=>'','__EVENTARGUMENT'=>'','__VIEWSTATE'=>$hidden['viewstate'],'__EVENTVALIDATION'=>$hidden['eventvalidation'],'NTUHWeb1$ButtonQuery'=>'查詢');
  $r->addPostFields($data);
  $r->send();
  $a=$r->getResponseBody();

  $dom=new DOMDocument;
  $dom->perserveWhiteSpace=FALSE;
  @$dom->loadHTML($a);
  foreach($dom->getElementsByTagName('input') as $element){
      if($element->getAttribute('name')=='NTUHWeb1$PatAccountListRecord1$personidHidden') $ID_no=$element->getAttribute('value');
  }
  $history="http://ihisaw.ntuh.gov.tw/WebApplication/OtherIndependentProj/PatientBasicInfoEdit/ReportResultQuery.aspx?SESSION=".$sessionid."&PatClass=I&PersonID=".$ID_no."&Hosp=T0&DefaultQuery=EMRContent";

  http_redirect($history);
?>
